Skip to content

[WIP] 3482 Add detection for circular macro replacement#4029

Open
Nic-Ma wants to merge 7 commits intoProject-MONAI:devfrom
Nic-Ma:3482-detect-circular-macro
Open

[WIP] 3482 Add detection for circular macro replacement#4029
Nic-Ma wants to merge 7 commits intoProject-MONAI:devfrom
Nic-Ma:3482-detect-circular-macro

Conversation

@Nic-Ma
Copy link
Copy Markdown
Contributor

@Nic-Ma Nic-Ma commented Mar 31, 2022

part of #3482

Description

Thanks for Gigon's suggestion, this PR added support to detect circular macro replacement in a config file.
And it also fixed a bug that missing the id arg in recursive operation, and now we don't do recursive logic for the case that macro text is in another config file.
Added many unit tests to cover the cases.

Status

Working in progress

Types of changes

  • Non-breaking change (fix or new feature that would not break existing functionality).
  • Breaking change (fix or new feature that would cause existing functionality to change).
  • New tests added to cover the changes.
  • Integration tests passed locally by running ./runtests.sh -f -u --net --coverage.
  • Quick tests passed locally by running ./runtests.sh --quick --unittests --disttests.
  • In-line docstrings updated.
  • Documentation updated, tested make html command in the docs/ folder.

@Nic-Ma
Copy link
Copy Markdown
Contributor Author

Nic-Ma commented Mar 31, 2022

/black

@Nic-Ma
Copy link
Copy Markdown
Contributor Author

Nic-Ma commented Mar 31, 2022

/build

1 similar comment
@Nic-Ma
Copy link
Copy Markdown
Contributor Author

Nic-Ma commented Mar 31, 2022

/build

Signed-off-by: Nic Ma <nma@nvidia.com>
@Nic-Ma
Copy link
Copy Markdown
Contributor Author

Nic-Ma commented Mar 31, 2022

/build

@Nic-Ma Nic-Ma requested review from ericspod, rijobro and wyli March 31, 2022 06:10
@Nic-Ma Nic-Ma changed the title 3482 Add detection for circular macro replacement 3482 [WIP] Add detection for circular macro replacement Mar 31, 2022
@Nic-Ma Nic-Ma changed the title 3482 [WIP] Add detection for circular macro replacement [WIP] 3482 Add detection for circular macro replacement Mar 31, 2022

"""
if waiting_list is None:
waiting_list = set()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If waiting_list is actually a list we could look at the previous item in the exception to help the user trace what's happened.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an interesting idea, I think the previous implementation in ReferenceResolver is a list and @wyli simplified it to set later. @wyli What do you think about it?

Thanks.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think set is more suitable/efficient for in checks here...not sure if the previous item is very intuitive when the circular ref is formed by multiple reference a->b->...->c->a

if not path:
# if the target id is in the waiting list, that's circular references
if ids in waiting_list:
raise ValueError(f"detected circular references in macro replacement '{ids}' for id='{id}'.")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this would be raise ValueError(f"Detected circular references in macro replacement '{ids}' for id='{id}'. (previous id='{waiting_list[-2]}'") or something like that.

@KumoLiu KumoLiu self-requested a review as a code owner January 30, 2026 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants